package dao;

import org.apache.ibatis.annotations.*;
import pojo.Wj;

import java.util.List;

@Mapper
/**
 * 问卷表数据访问接口
 */
public interface WjMapper {
    // 根据id查询问卷
    @Select("SELECT * FROM wj WHERE id = #{id}")
    Wj findWjById(Integer id);

    // 查询所有问卷
    @Select("SELECT * FROM wj ORDER BY create_time DESC")
    List<Wj> findAllWj();

    // 新增问卷
    @Insert("INSERT INTO wj (question, option1, option2, option3, option4) " +
            "VALUES (#{question}, #{option1}, #{option2}, #{option3}, #{option4})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int addWj(Wj wj);

    // 更新问卷
    @Update("UPDATE wj SET " +
            "question = #{question}, " +
            "option1 = #{option1}, " +
            "option2 = #{option2}, " +
            "option3 = #{option3}, " +
            "option4 = #{option4} " +
            "WHERE id = #{id}")
    int updateWj(Wj wj);

    // 删除问卷
    @Delete("DELETE FROM wj WHERE id = #{id}")
    int deleteWj(Integer id);
}